package com.scuec.groupfive.mapper;

import com.scuec.groupfive.entity.UserFeedback;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface FeedbackMapper {

    @Select("SELECT f.*, u.username " +
            "FROM user_feedbacks f " +  // 修正了表别名，使用f代替uf
            "JOIN users u ON f.user_id = u.user_id " +
            "ORDER BY f.created_at DESC")
    List<UserFeedback> getFeedbackList();

    @Insert("INSERT INTO user_feedbacks (user_id, username, feedback_type, title, content, status, admin_reply, created_at, updated_at) " +
            "VALUES (#{userId}, #{username}, #{feedbackType}, #{title}, #{content}, 'PENDING', '', NOW(), NOW())")
    int insertFeedback(UserFeedback feedback);

    @Select("SELECT f.*, u.username " +
            "FROM user_feedbacks f " +
            "JOIN users u ON f.user_id = u.user_id " +
            "WHERE f.user_id = #{userId} " +
            "ORDER BY f.created_at DESC")
    List<UserFeedback> getFeedbackByUserId(@Param("userId") String userId);
}